"use strict";

module.exports = (app) => {
  class Service extends app.Service {
    //  根据用户名名获取用户信息（判断是否注册过）
    async getUserByName(username) {
      const { app } = this;
      try {
        const result = await app.mysql.get("user", { username });
        return result;
      } catch (error) {
        console.log(error);
        return null;
      }
    }

    // 注册
    async register(params) {
      const { app } = this;
      try {
        return await app.mysql.insert("user", params);
      } catch (error) {
        console.log(error);
        return null;
      }
    }
    async editUserInfo(newUserInfo) {
      //修改用户信息
      const { app } = this;
      try {
        // console.log(newUserInfo);
        return await app.mysql.update(
          "user",
          { ...newUserInfo },
          { id: newUserInfo.id }
        );
      } catch (error) {
        console.log(error);
        return null;
      }
    }
  }
  return Service;
};
